<template>
  <div class="box">
    <div class="topBar">
      <div class="topBox">
        <div>
          <span class="khTitle">客户信息</span>
          <span class="khInput" @click="khFn">{{
            customerInfo.customerNM
          }}</span>
        </div>
        <div class="searchBtn">
          <el-button type="primary" class="btn" @click="clearFn"
            >重置</el-button
          >
        </div>
      </div>
    </div>
    <div class="right">
      <!-- 客户信息 -->
      <div class="bondCard">
        <div class="customersCardTitle">客户信息</div>
        <div class="info">
          <div class="infoItem">
            <div style="margin-bottom: 20px">
              <span class="infoItemLabel">客户全称</span
              ><span class="infoItemVal">{{ customerInfo.customerNM }}</span>
            </div>
            <div style="margin-bottom: 20px">
              <span class="infoItemLabel">客户编码</span
              ><span class="infoItemVal">{{ customerInfo.customerID }}</span>
            </div>
            <div>
              <span class="infoItemLabel">公司地址</span
              ><span class="infoItemVal">{{ customerInfo.comAddress }}</span>
            </div>
          </div>
          <div class="infoItem">
            <!-- <div style="margin-bottom: 20px">
              <span class="infoItemLabel">信用评级</span
              ><span class="infoItemVal">{{ customerInfo.custRating }}</span>
            </div> -->
            <div style="margin-bottom: 20px">
              <span class="infoItemLabel">累计销售规模</span
              ><span class="infoItemVal">{{
                customerInfo.cumlativeAmount | filterNum
              }}</span>
            </div>
            <div>
              <span class="infoItemLabel">累计销售只数</span
              ><span class="infoItemVal">{{ customerInfo.cumlativeSize }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="tableBox">
        <el-table :data="tableData" class="tableBoxChild">
          <el-table-column label="序号" align="center" type="index">
          </el-table-column>
          <el-table-column prop="bondId" label="债券编码" align="center">
          </el-table-column>
          <el-table-column prop="bondFname" label="债券名称" align="center">
          </el-table-column>
          <el-table-column prop="bondSname" label="债券简称" align="center">
          </el-table-column>
          <!-- <el-table-column label="发行规模(万元)" align="center" :formatter="fxgmFn"> -->
          <el-table-column
            label="发行规模(万元)"
            align="center"
            :formatter="formatterNum"
          >
          </el-table-column>
          <el-table-column prop="bondType" label="债券类型" align="center">
          </el-table-column>
          <el-table-column prop="termDays" label="期限（天）" align="center">
          </el-table-column>
          <el-table-column prop="assessMethod" label="推荐规则" align="center">
          </el-table-column>
          <el-table-column label="推荐指数" align="center" :formatter="glFn">
          </el-table-column>
        </el-table>
        <el-pagination
          small
          background
          layout="prev, pager, next"
          :total="total"
          @current-change="pageFn"
        >
        </el-pagination>
      </div>
    </div>
    <el-drawer
      ref="drawer"
      title="请选择客户信息"
      size="80%"
      :visible.sync="drawer"
      direction="btt"
      :append-to-body="true"
      :destroy-on-close="true"
      custom-class="drawer-table"
    >
      <div>
        <el-form :inline="true" :model="customerForm">
          <el-form-item label="客户名称">
            <el-input v-model="customerForm.customerNM" clearable></el-input>
          </el-form-item>
          <el-form-item label="客户ID">
            <el-input v-model="customerForm.customerId" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="customerSubmit" class="btn"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
        <el-table
          ref="singleTable"
          :data="searchList"
          :highlight-current-row="true"
          style="width: 100%"
          @row-click="customerRowClick"
        >
          <el-table-column type="index" label="序号" align="center">
          </el-table-column>
          <el-table-column property="customerId" label="客户ID" align="center">
          </el-table-column>
          <el-table-column
            property="customerNm"
            label="客户名称"
            align="center"
          >
          </el-table-column>
        </el-table>
        <el-pagination
          small
          style="text-align: right; margin-right: 20px; margin-top: 20px"
          background
          layout="prev, pager, next"
          :total="customerTotal"
          @current-change="customerPageFn"
        >
        </el-pagination>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import { getCustomer } from "@/api/common/index.js";
import {
  queryCustomerProbabilityDetail,
  newCustomerInfo,
} from "@/api/recommendationSystem/index.js";
export default {
  data() {
    return {
      drawer: false,
      searchList: [],
      tableData: [],
      searchInput: "",
      total: 0,
      customerInfo: {},
      count: "",
      customerTotal: 0,
      customerForm: {
        customerNM: "",
        customerId: "",
      },
    };
  },
  filters: {
    filterNum(value) {
      const str = value ? value.toString() : "";
      if (str) {
        const reg =
          str.indexOf(".") > -1 ? /\B(?=(\d{3})+\.)/g : /\B(?=(\d{3})+$)/g;
        const returnData = str.replace(reg, ",");
        return returnData;
      } else {
        return "";
      }
    },
  },
  mounted() {
    // this.getCustomer("")
  },
  methods: {
    khFn() {
      this.drawer = true;
      const param = {
        customer_nm: "",
        customer_id: "",
        page: 1,
        pn: 10,
      };
      this.getCustomerFn(param);
    },
    pageFn(currentPage) {
      const param = {
        customerId:
          this.customerInfo.customerID || this.customerInfo.customerId,
        page: currentPage,
        pn: 10,
      };
      queryCustomerProbabilityDetail(param).then((res) => {
        this.tableData = res.data.result;
        this.total = Number(res.data.totalResults);
      });
    },
    customerSubmit() {
      const param = {
        // ...this.customerForm,
        customer_nm: this.customerForm.customerNM,
        customer_id: this.customerForm.customerId,
        page: 1,
        pn: 10,
      };
      this.getCustomerFn(param);
    },
    customerPageFn(page) {
      const param = {
        // ...this.customerForm,
        customer_nm: this.customerForm.customerNM,
        customer_id: this.customerForm.customerId,
        page: page,
        pn: 10,
      };
      this.getCustomerFn(param);
    },
    glFn(row) {
      // return row.assessRate + "%";
      return Number(Number(row.assessRate) * 100).toFixed(2);
    },
    formatterNum(row, cloumn, cellValue, index) {
      const str = cellValue ? cellValue * 1000 : "";
      if (str) {
        const reg =
          str.indexOf(".") > -1 ? /\B(?=(\d{3})+\.)/g : /\B(?=(\d{3})+$)/g;
        const returnData = str.replace(reg, ",");
        return returnData;
      } else {
        return "";
      }
    },
    fxgmFn(row) {
      return row.issueAmount + "000万元";
    },
    clearFn() {
      this.customerInfo = {};
      this.tableData = [];
    },
    customerRowClick(row) {
      this.drawer = false;
      // this.customerInfo = row;
      getCustomer({
        customerNM: row.customerNm,
        customerId: row.customerId,
      }).then((res) => {
        this.customerInfo = res.data.result[0];
      });
      const param = {
        customerId: row.customerId,
        page: 1,
        pn: 10,
      };
      queryCustomerProbabilityDetail(param).then((res) => {
        this.tableData = res.data.result;
        this.total = Number(res.data.totalResults);
      });
    },
    getCustomerFn(param) {
      newCustomerInfo(param).then((res) => {
        this.searchList = res.data.result;
        this.customerTotal = Number(res.data.totalResults);
      });
    },
    searchInputFn() {
      this.count = "";
      this.getCustomer(this.searchInput);
    },
    clickFn(v, i) {
      this.clearFn();
      this.count = i;
      this.customerInfo = {
        ...v,
      };
      queryCustomerProbabilityDetail({ customerId: v.customerID }).then(
        (res) => {
          this.tableData = res.data.result;
          this.total = Number(res.data.totalResults);
        }
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.el-table ::v-deep th.el-table__cell {
  background-color: #1c2238 !important;
  color: #fff;
}

.box {
  .topBar {
    min-height: 80px;
    background-color: #262d47;
    margin-bottom: 10px;
    padding: 20px 20px;
    padding-left: 40px;
    padding-bottom: 10px;
  }

  .topBox {
    display: flex;

    span {
      display: inline-block;
    }

    .searchBtn {
      margin-left: 20px;
    }

    .zj {
      margin-left: 20px;
    }

    .khTitle {
      height: 30px;
      line-height: 30px;
      vertical-align: top;
      color: #ffffff;
      font-size: 14px;
      font-weight: 700px;
      margin-right: 10px;
    }

    .khInput,
    .zjInput {
      height: 30px;
      line-height: 30px;
      width: 200px;
      overflow: hidden;
      border: 1px solid rgba(126, 163, 255, 0.3);
      color: #ffffff;
      background-color: #363657;
      border-radius: 3px;
      cursor: pointer;
      text-align: center;
      line-height: 30px;
      padding: 0px 10px;
      font-size: 12px;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .zjTitle {
      height: 30px;
      line-height: 30px;
      vertical-align: top;
      color: #ffffff;
      font-size: 14px;
      font-weight: 700px;
      margin-right: 10px;
    }
  }

  .left {
    width: 240px;
    background-color: #262d47;
    height: 100%;
  }

  .right {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .searchList {
    padding-top: 10px;
    padding-left: 10px;
    padding-right: 10px;
    height: 700px;
    overflow: scroll;

    .searchListItem {
      height: 35px;
      line-height: 35px;
      text-align: center;
      color: #959fc5;
      font-size: 12px;
      overflow: hidden; //超出隐藏
      white-space: nowrap; //不折行
      text-overflow: ellipsis; //溢出显示省略号
    }

    .searchListItem:hover {
      background: #1f9bfd !important;
      color: #fff;
      cursor: pointer;
    }
  }

  .searchListItemAct {
    background: #1f9bfd !important;
    color: #fff !important;
  }

  .bondCard {
    background-color: #262d47;
    color: #ffffff;
    margin-bottom: 10px;

    .info {
      display: flex;
      padding: 15px 20px;

      .infoItem {
        flex: 1;
      }
    }

    .infoItemLabel {
      margin-right: 30px;
      font-size: 14px;
    }

    .infoItemVal {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #d6dcff;
    }
  }

  .el-table ::v-deep th.el-table__cell {
    background-color: #1c2238 !important;
    color: #fff;
  }

  .tableBox {
    background-color: #262d47;
    flex: 1;
    padding: 15px 10px;
  }

  .tableBoxChild {
    min-height: 500px;
  }

  .el-pagination {
    text-align: right;
  }

  .leftTitle {
    height: 40px;
    line-height: 40px;
    background: #354060;
    font-size: 14px;
    font-family: PingFang-SC-Bold, PingFang-SC;
    font-weight: bold;
    color: #ffffff;
    padding-left: 17px;
    margin-bottom: 10px;
  }

  .customersCardTitle {
    height: 40px;
    background: #354060;
    font-size: 14px;
    font-family: PingFang-SC-Bold, PingFang-SC;
    font-weight: bold;
    color: #ffffff;
    padding: 10px 16px;
  }
}
</style>
